<!-- eslint-disable vue/multi-word-component-names -->
<!-- eslint-disable vue/no-v-model-argument -->
<template>
  <van-popup v-model:show="show" round closeable>
    <div class="popup-main">
      <div class="title">绑定</div>
      <input type="text" v-model="value" placeholder="請輸入地址" />
      <div
        class="button"
        :class="{ disabled: value === '' }"
        @click="handleConfirm"
      >
        確認
      </div>
    </div>
  </van-popup>
</template>

<script>
import { send } from "@/utils/web3";
import { mapState } from "vuex";
export default {
  computed: {
    ...mapState({
      walletAddress: (state) => state.user.walletAddress,
    }),
  },
  data() {
    return {
      show: false,
      value: "",
    };
  },
  methods: {
    open() {
      this.value = this.$route.query?.address || "";
      this.show = true;
    },
    close() {
      this.show = false;
    },
    handleConfirm() {
      send({
        methodName: "setsuperior",
        from: this.walletAddress,
        data: this.value,
      })
        // eslint-disable-next-line no-unused-vars
        .then((res) => {
          this.$toast.success("绑定成功");
          this.$emit("update");
          this.close();
        })
        // eslint-disable-next-line no-unused-vars
        .catch((err) => {
          // console.log(err);
        });
    },
  },
};
</script>

<style lang="scss" scoped>
.popup-main {
  width: 90vw;
  padding: 50px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  .title {
    font-size: 32px;
    font-weight: 600;
    color: #2c2c2c;
  }
  input {
    width: 100%;
    height: 104px;
    background: #f4f6fa;
    border-radius: 16px;
    font-size: 28px;
    text-align: center;
    margin: 32px 0 0 16px;
    border: 0;
  }
  .button {
    width: 100%;
    height: 100px;
    background: #090d18;
    border-radius: 16px;
    margin: 40px 0 0 16px;
    color: #ffffff;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 30px;
    &.disabled {
      opacity: 0.5;
      pointer-events: none;
    }
  }
}
</style>
